fix: add key validation and preserve exception chains in workflow models#226
Open
crazywriter1 wants to merge 1 commit intoOpenGradient:mainfrom
Open
fix: add key validation and preserve exception chains in workflow models#226crazywriter1 wants to merge 1 commit intoOpenGradient:mainfrom
crazywriter1 wants to merge 1 commit intoOpenGradient:mainfrom
Conversation
_extract_number() helper validates key existence before access, preventing bare KeyError. read_workflow_wrapper() now catches KeyError separately and uses 'from e' to preserve the original exception chain. Signed-off-by: crazywriter1 <crazywriter1@users.noreply.github.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
read_btc_1_hour_price_forecast) accessedresult.numbers["key"]directly without checking if the key exists, causing a bareKeyErrorwith no context when the workflow output is missing the expected field_extract_number()helper that validates key existence before access and raises a descriptiveKeyErrorlisting available keysread_workflow_wrapper()had a broadexcept Exceptionthat converted every error (includingKeyError) into a genericRuntimeError, losing the original error type and tracebackKeyErrorseparately so callers can distinguish "missing output key" from "network/contract failure"from eto both exception paths to preserve the full exception chain for debuggingChanged files
src/opengradient/workflow_models/workflow_models.py— added_extract_number()helper, replaced all 7 rawx.numbers["key"]accessessrc/opengradient/workflow_models/utils.py— addedKeyErrorhandler, addedfrom echaining, updated docstringtests/workflow_models_test.py— new test file with 7 testsTest plan
test_extracts_valid_key— happy path extractiontest_raises_on_missing_key— KeyError with descriptive messagetest_raises_on_missing_numbers_attr— handles result without.numberstest_reports_available_keys— error message lists available keystest_keyerror_preserved_not_converted_to_runtime— KeyError stays KeyErrortest_runtime_error_chains_original—__cause__is set viafrom etest_success_returns_workflow_output— happy path returns correct output